package com.qf.springbootdemo03.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @author q
 * @version V1.0
 * @date 2021/11/25
 **/
//@Configuration
public class SecurityConfig01 extends WebSecurityConfigurerAdapter {

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {

        //密码加密
        String password = passwordEncoder.encode("123456");

        //基于内存设置用户名与密码，必须为用户设置角色，否则会报错【非法参数，没有角色】
        // Authentication --> 认证
        auth.inMemoryAuthentication().withUser("jack").password(password).roles("");

    }
}
